package org.lanqiao.Filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.bean.EduManager;
import org.lanqiao.bean.EduTeacherBean;
import org.lanqiao.bean.EduUserBean;
import org.lanqiao.myUtils.Myutils;

public class CheckLoginFilter implements Filter {

	@Override
	public void destroy() {

	}

	@Override
	public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain chain)
			throws IOException, ServletException {
		// 获取登录的信息
		HttpServletRequest request = (HttpServletRequest) arg0;
		EduManager em = (EduManager) request.getSession().getAttribute("loginedManager");
		EduUserBean eub=(EduUserBean) request.getSession().getAttribute("StudentInfo");
		EduTeacherBean etb=(EduTeacherBean) request.getSession().getAttribute("TeacherBean");
		// 验证登录的信息是否合法
		if ((em != null && em.getManagername() != null)||(eub!=null&&eub.getUsername()!=null)||(etb!=null&&etb.getTeachername()!=null)) {
			chain.doFilter(arg0, arg1);
		} else {
			((HttpServletResponse) arg1).sendRedirect("./../login.jsp");
		}

	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub

	}

}
